<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
 */
$api = app('Dingo\Api\Routing\Router');

// v1 version API
// add in header    Accept:application/vnd.lumen.v1+json
$api->version('v1', [
    'namespace' => 'App\Http\Controllers\Api\V1',
    'middleware' => [
        //'cors',
        'serializer',
         //'serializer:array', // if you want to remove data wrap
        'api.throttle',
    ],
    // each route have a limit of 20 of 1 minutes
    'limit' => 200, 'expires' => 1,
], function ($api) {
    // Auth
	
    // login
    $api->post('authorizations', [
        'as' => 'authorizations.store',
        'uses' => 'AuthController@store',
    ]);

    // User
    $api->post('users', [
        'as' => 'users.store',
        'uses' => 'UserController@store',
    ]);
	// User phone register
	$api->post('user/register', [
	    'as' => 'users.register',
	    'uses' => 'UserController@register',
	]);

    // user list
    $api->get('users', [
        'as' => 'users.index',
        'uses' => 'UserController@index',
    ]);
    // user detail
    $api->get('users/{id}', [
        'as' => 'users.show',
        'uses' => 'UserController@show',
    ]);

    // POST
    // post list
    $api->get('posts', [
        'as' => 'posts.index',
        'uses' => 'PostController@index',
    ]);
    // post detail
    $api->get('posts/{id}', [
        'as' => 'posts.show',
        'uses' => 'PostController@show',
    ]);

    // POST COMMENT
    // post comment list
	$api->get('posts/{conId}/comments', [
	    'as' => 'posts.comments.index',
	    'uses' => 'CommentController@index',
	]);

    $api->get('comments/index', [
        'as' => 'comments.index',
        'uses' => 'CommentController@index',
    ]);

    /*
     * 对于authorizations 并没有保存在数据库，所以并没有id，那么对于
     * 刷新（put) 和 删除（delete) 我没有想到更好的命名方式
     * 所以暂时就是 authorizations/current 表示当前header中的这个token。
     * 如果 token 保存在数据库，那么就是 authorizations/{id}，像 github 那样。
     */
    $api->put('authorizations/current', [
        'as' => 'authorizations.update',
        'uses' => 'AuthController@update',
    ]);

    // need authentication
    $api->group(['middleware' => 'api.auth'], function ($api) {
        /*
         * 对于authorizations 并没有保存在数据库，所以并没有id，那么对于
         * 刷新（put) 和 删除（delete) 我没有想到更好的命名方式
         * 所以暂时就是 authorizations/current 表示当前header中的这个token。
         * 如果 token 保存在数据库，那么就是 authorizations/{id}，像 github 那样。
         */
        $api->delete('authorizations/current', [
            'as' => 'authorizations.destroy',
            'uses' => 'AuthController@destroy',
        ]);

        // USER
        // my detail
        $api->get('user', [
            'as' => 'user.show',
            'uses' => 'UserController@userShow',
        ]);

        // update part of me
        $api->post('user/update', [
            'as' => 'user.update',
            'uses' => 'UserController@update',
        ]);
        // update my password
        $api->post('user/password', [
            'as' => 'user.password.update',
            'uses' => 'UserController@editPassword',
        ]);

		// user's address list
        $api->get('user/address', [
            'as' => 'user.address.index',
            'uses' => 'AddressController@index',
        ]);
		$api->post('user/address/add', [
		    'as' => 'user.address.add',
		    'uses' => 'AddressController@add',
		]);
		$api->post('user/head/upload', [
		    'as' => 'user.head.upload',
		    'uses' => 'UploadController@user_head',
		]);

        // POST
        // user's posts index
        $api->get('user/posts', [
            'as' => 'user.posts.index',
            'uses' => 'PostController@userIndex',
        ]);
        // create a post
        $api->post('posts', [
            'as' => 'posts.store',
            'uses' => 'PostController@store',
        ]);
        // update a post
        $api->put('posts/{id}', [
            'as' => 'posts.update',
            'uses' => 'PostController@update',
        ]);
        // update part of a post
        $api->patch('posts/{id}', [
            'as' => 'posts.patch',
            'uses' => 'PostController@patch',
        ]);
        // delete a post
        $api->delete('posts/{id}', [
            'as' => 'posts.destroy',
            'uses' => 'PostController@destroy',
        ]);
        // POST COMMENT
        // create a comment
        $api->post('posts/{conId}/comments', [
            'as' => 'posts.comments.store',
            'uses' => 'CommentController@store',
        ]);
		
		$api->post('posts/{commentId}/comments/like', [
		    'as' => 'posts.comments.like',
		    'uses' => 'CommentController@like',
		]);
		
        $api->put('posts/{conId}/comments/{id}', [
            'as' => 'posts.comments.update',
            'uses' => 'CommentController@update',
        ]);
        // delete a comment
        $api->delete('posts/{conId}/{conType}/comments/{id}', [
            'as' => 'posts.comments.destroy',
            'uses' => 'CommentController@destroy',
        ]);
		
		//标志已读
		$api->post('notice/readed', [
			'as' => 'notice.readed',
			'uses' => 'NoticeController@readed',
		]);
		//标志已删除
		$api->post('notice/deleted', [
			'as' => 'notice.deleted',
			'uses' => 'NoticeController@deleted',
		]);
		//标志已读
		$api->post('news/readed', [
			'as' => 'news.readed',
			'uses' => 'NewsController@readed',
		]);
		//标志已删除
		$api->post('news/deleted', [
			'as' => 'news.deleted',
			'uses' => 'NewsController@deleted',
		]);
		$api->get('product/my_coupon_number', [
			'as' => 'product.my_coupon_number',
			'uses' => 'ProductController@myCouponNumber'
		]);
		$api->get('product/get_my_coupons', [
			'as' => 'product.get_my_coupons',
			'uses' => 'ProductController@getMyCoupons'
		]);
		$api->get('product/use_my_coupon', [
			'as' => 'product.use_my_coupon',
			'uses' => 'ProductController@useMyCoupon'
		]);
    });
	// add new route by sevenpan
	$api->get('product/carousels', [
		'as' => 'product.carousels',
		'uses' => 'ProductController@carousels',
	]);
	$api->get('product/categories', [
		'as' => 'product.categoriest',
		'uses' => 'ProductController@categories'
	]);
	$api->get('product/index', [
		'as' => 'product/index',
		'uses' => 'ProductController@index'
	]);
	$api->get('product/detail', [
		'as' => 'product/detail',
		'uses' => 'ProductController@detail'
	]);
	$api->post('product/fetch_coupon', [
		'as' => 'product/fetch_coupon',
		'uses' => 'ProductController@fetchCoupon'
	]);
	$api->get('product/redis_test', [
		'as' => 'product/redis_test',
		'uses' => 'ProductController@redisTest'
	]);
	//index
	$api->get('index/recommends', [
		'as' => 'index/recommends',
		'uses' => 'IndexController@recommends'
	]);
	//shop 
	$api->get('shop/detail', [
		'as' => 'shop/detail',
		'uses' => 'ShopController@detail'
	]);
	$api->post('shop/fetch_coupon', [
		'as' => 'shop/fetch_coupon',
		'uses' => 'ShopController@fetchCoupon'
	]);
	// code captcha
	$api->post('code/pcaptcha', [
	    'as' => 'code.pcaptcha',
	    'uses' => 'CodeController@pcaptcha',
	]);
	$api->post('code/dxcaptcha', [
	    'as' => 'code.dxcaptcha',
	    'uses' => 'CodeController@dxcaptcha',
	]);
	$api->post('notice/list', [
		'as' => 'notice.list',
		'uses' => 'NoticeController@index',
	]);
	$api->post('notice/detail', [
		'as' => 'notice.detail',
		'uses' => 'NoticeController@detail',
	]);
	$api->post('news/list', [
		'as' => 'news.list',
		'uses' => 'NewsController@index',
	]);
	$api->post('news/detail', [
		'as' => 'news.detail',
		'uses' => 'NewsController@detail',
	]);
	$api->get('city/get_all', [
		'as' => 'city/get_all',
		'uses' => 'CityController@getAll'
	]);
	
	
	//course
	$api->get('cuser', [
	    'as' => 'cuser.show',
	    'uses' => 'CuserController@show',
	]);
	// login
	$api->post('cuser/register', [
	    'as' => 'cuser.register',
	    'uses' => 'CuserController@register',
	]);
	$api->post('cuser/login', [
	    'as' => 'cuser.login',
	    'uses' => 'CuserController@login',
	]);
	
	$api->post('course/index', [
		'as' => 'course.index',
		'uses' => 'CourseController@index',
	]);
	$api->post('course/detail', [
		'as' => 'course.detail',
		'uses' => 'CourseController@detail',
	]);
	$api->post('courseuser/add', [
		'as' => 'courseuser.add',
		'uses' => 'CourseUserController@add',
	]);
	$api->post('courseuser/list', [
		'as' => 'courseuser.list',
		'uses' => 'CourseUserController@index',
	]);
	$api->post('courseuser/learn', [
		'as' => 'courseuser.learn',
		'uses' => 'CourseUserController@learn',
	]);
	
	
	$api->post('pay/xorpay_add', [
		'as' => 'pay.xorpay_add',
		'uses' => 'PayController@xorpay_add',
	]);
	$api->post('pay/xorpay_notify', [
		'as' => 'pay.xorpay_notify',
		'uses' => 'PayController@xorpay_notify',
	]);
	
	$api->post('pay/ali_add', [
		'as' => 'pay.ali_add',
		'uses' => 'PayController@ali_add',
	]);
	$api->post('pay/ali_notify', [
		'as' => 'pay.ali_notify',
		'uses' => 'PayController@ali_notify',
	]);
	$api->post('pay/ali_return', [
		'as' => 'pay.ali_return',
		'uses' => 'PayController@ali_return',
	]);
});


// v1 version API
// add in header    Accept:application/vnd.lumen.v1+json
$api->version('v2', [
    'namespace' => 'App\Http\Controllers\Api\V2',
    'middleware' => [
        //'cors',
        'serializer',
         //'serializer:array', // if you want to remove data wrap
        'api.throttle',
    ],
    // each route have a limit of 20 of 1 minutes
    'limit' => 200, 'expires' => 1,
], function ($api) {
    // Auth
	
    // login
    $api->post('authorizations', [
        'as' => 'authorizations.store',
        'uses' => 'AuthController@store',
    ]);

	// code captcha
	$api->post('code/pcaptcha', [
	    'as' => 'code.pcaptcha',
	    'uses' => 'CodeController@pcaptcha',
	]);

    // User 邮箱 账号 密码注册
    $api->post('user', [
        'as' => 'users.store',
        'uses' => 'UserController@store',
    ]);

	// User phone register
	$api->post('user/register', [
	    'as' => 'users.register',
	    'uses' => 'UserController@register',
	]);
	// User forgot password
	$api->post('user/forgot', [
	    'as' => 'users.forgot',
	    'uses' => 'UserController@forgot',
	]);

	// User email confirm reset password
	$api->get('password/confirm_reset', [
	    'as' => 'users.confirm_reset',
	    'uses' => 'UserController@confirm_reset',
	]);

    // user list
    $api->get('users', [
        'as' => 'users.index',
        'uses' => 'UserController@index',
    ]);
    // user detail
    $api->get('users/{id}', [
        'as' => 'users.show',
        'uses' => 'UserController@show',
    ]);

    // POST
	// tag list
    $api->get('tags', [
        'as' => 'tags.index',
        'uses' => 'TagController@index',
    ]);
    //anchor list
    $api->get('anchors', [
        'as' => 'anchors.index',
        'uses' => 'XoAnchorsController@index',
    ]);
    $api->get('pay/confs', [
        'as' => 'pay.confs',
        'uses' => 'XoPayController@index',
    ]);

    //video list
    $api->get('videos', [
        'as' => 'videos.index',
        'uses' => 'XoAnchorVideoController@index',
    ]);

    // post list
    $api->get('posts', [
        'as' => 'posts.index',
        'uses' => 'PostController@index',
    ]);
    // post detail
    $api->get('posts/{id}', [
        'as' => 'posts.show',
        'uses' => 'PostController@show',
    ]);

    // POST COMMENT
    // post comment list
	$api->get('posts/{conId}/comments', [
	    'as' => 'posts.comments.index',
	    'uses' => 'CommentController@index',
	]);

    $api->get('comments/index', [
        'as' => 'comments.index',
        'uses' => 'CommentController@index',
    ]);

    /*
     * 对于authorizations 并没有保存在数据库，所以并没有id，那么对于
     * 刷新（put) 和 删除（delete) 我没有想到更好的命名方式
     * 所以暂时就是 authorizations/current 表示当前header中的这个token。
     * 如果 token 保存在数据库，那么就是 authorizations/{id}，像 github 那样。
     */
    $api->put('authorizations/current', [
        'as' => 'authorizations.update',
        'uses' => 'AuthController@update',
    ]);

    // need authentication
    $api->group(['middleware' => 'api.auth'], function ($api) {
        /*
         * 对于authorizations 并没有保存在数据库，所以并没有id，那么对于
         * 刷新（put) 和 删除（delete) 我没有想到更好的命名方式
         * 所以暂时就是 authorizations/current 表示当前header中的这个token。
         * 如果 token 保存在数据库，那么就是 authorizations/{id}，像 github 那样。
         */
        $api->delete('authorizations/current', [
            'as' => 'authorizations.destroy',
            'uses' => 'AuthController@destroy',
        ]);

        // USER 用户信息
        // my detail
        $api->get('user', [
            'as' => 'user.show',
            'uses' => 'UserController@userShow',
        ]);


    });
});
